﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vowei.Core.Models;

namespace Vowei.Data
{
    public class TicketStatusManager : ITicketStatusManager
    {
        // 这个类型之所以放在Vowei.Data.Models命名空间，而不是放在Vowei.Core.Models
        // 是因为我们将Task的状态定义成一个string类型，允许第三方开发自行根据适合自己的
        // 的需求来定义任务状态。而Vowei.Data这个项目，可以看作是Vowei.Core里面的一些
        // 类型的具体实现，在系统运行的时候，可以被其他类似的模块替换掉。
        private static Dictionary<string, int> _taskStatusDefinitions;
        public Dictionary<string, int> TaskStatusDefinitions
        {
            get
            {
                if (_taskStatusDefinitions == null)
                {
                    _taskStatusDefinitions = new Dictionary<string, int>();
                    _taskStatusDefinitions.Add("Not Started", 1);
                    _taskStatusDefinitions.Add("Accepted", 2);
                    _taskStatusDefinitions.Add("Rejected", 4);
                    _taskStatusDefinitions.Add("In Progress", 2);
                    _taskStatusDefinitions.Add("Under Review", 5);
                    _taskStatusDefinitions.Add("Completed", 3);
                    _taskStatusDefinitions.Add("Closed", 3);
                    _taskStatusDefinitions.Add("Deferred", 4);
                    _taskStatusDefinitions.Add("Canceled", 4);
                }

                return _taskStatusDefinitions;
            }
        }

        public void Cancel(Ticket ticket)
        {
            ticket.Status = "Canceled";
        }

        public void Accept(Ticket ticket)
        {
            ticket.Status = "Accepted";
        }

        public void Close(Ticket ticket)
        {
            Close(ticket, DateTime.Now);
        }

        public void Close(Ticket ticket, DateTime closeDate)
        {
            ticket.Progress = 1.0f;
            ticket.ClosedDate = closeDate;
            ticket.Status = "Closed";
        }

        public void Complete(Ticket ticket)
        {
            Close(ticket);
            ticket.Status = "Completed";
        }

        public void ReActive(Ticket ticket)
        {
            throw new NotImplementedException();
        }
    }
}
